package com.airsystem.pos.bengkel.model.dialog;

import java.awt.GridBagLayout;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import com.airsystem.pos.bengkel.component.DialogFrame;
import com.airsystem.pos.bengkel.entity.JenisTagihan;

/**
 * @author Fanny Irawan Sutawanir (fannyirawans@gmail.com)
 */
public class MasterBillingDialogModel extends DialogFrame {
	protected int row = 0;

	protected GridBagLayout baseLayout = new GridBagLayout();
	protected GridBagLayout tableLayout = new GridBagLayout();

	protected JPanel basePanel = new JPanel();
	protected JPanel tablePanel = new JPanel();

	protected JScrollPane tableScroll = new JScrollPane();

	protected JTable tableData = new JTable();

	protected JLabel searchLabel = new JLabel();

	protected JComboBox searchCombo = new JComboBox();

	protected JTextField searchField = new JTextField();

	protected JButton searchButton = new JButton();

	protected DefaultTableModel tableModel = new DefaultTableModel(new Object[][] {},
																   new String[] { "Jenis Tagihan", "ID" }) {

		boolean[] canEdit = new boolean[] { false, false };

		public boolean isCellEditable(int rowIndex, int columnIndex) {
			return canEdit[columnIndex];
		}
	};

	private JenisTagihan jenisTagihan;

	public JenisTagihan getJenisTagihan() {
		return jenisTagihan;
	}

	public void setJenisTagihan(JenisTagihan jenisTagihan) {
		this.jenisTagihan = jenisTagihan;
	}

	protected JenisTagihan getComponentData() {
		JenisTagihan jenisTagihan = new JenisTagihan();
		jenisTagihan.setNama(searchField.getText());

		return jenisTagihan;
	}

	protected JenisTagihan getSearchData() {
		JenisTagihan jenisTagihan = new JenisTagihan();
		jenisTagihan.setChoice(searchCombo.getSelectedIndex());

		String input = searchField.getText().trim();

		switch (searchCombo.getSelectedIndex()) {
		case 0: {
			jenisTagihan.setNama(input);
			break;
		}

		default:
			throw new IllegalArgumentException("Search is empty");
		}

		return jenisTagihan;
	}
}